const app = getApp()

let pageNo = 1;

Page({
  data: {
    orderList: [],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    printOrder: false,
    cancelOrder: false,
    mark: '',
    deliveryNoteid: '',
    pageLoad: false,
    showMenu:true,
     
  },

  backOrder: function(e) {
    console.log(e)
    var that = this;
    let id = e.currentTarget.id
    var orderlist = that.data.orderList;
    console.log(id)
    that.setData({

      cancelOrder: true
    })
    // 取消单笔订单
    // for (var i = 0; i < orderlist.length; i++) {

    //   if (orderlist[i].id == id) {
    //     console.log('2')
    //     let list = orderlist;
    //     list[i].cancelOrder = true;
    //     console.log(list)
    //     that.setData({
    //       orderList: list,
    //       cancelOrder:true
    //     })
    //   }
    // }
    wx.showToast({
      title: '请填写退单原因',
    })
  },
  setmark: function(e) {

  },
  cancelbackOrder: function(e) {
    console.log(e)
    var that = this;
    let id = e.currentTarget.id
    var orderlist = that.data.orderList;
    console.log(id)
    that.setData({

      cancelOrder: false
    })
    // 
    // for (var i = 0; i < orderlist.length; i++) {
    //   if (orderlist[i].id == id) {
    //     let list = orderlist;
    //     list[i].cancelOrder = false;
    //     console.log(list)
    //     that.setData({
    //       orderList: list,
    //     })
    //   }
    // }
  },
  postOrder: function(e) {
    var that = this;
    wx.request({
      url: app.data.baseUrl + '/transaction/DeliveryNoteMgrAction!deliverSure',
      method: 'get',
      data: {
        'deliveryNote.id': that.data.deliveryNoteid,
        'deliveryNote.deliver_sure_descr': that.data.mark
      },
      header: app.globalData.header,
      success: function(res) {
        var msg = res.data.msg;
        // console.log(res);
        // console.log('postOrder')
        wx.showToast({
          title: msg,
        })
      },
      fail: function(e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })

    that.setData({
      printOrder: true,
    })
    
  },
  // setmark: function(e) {
  //   console.log(e)
  //   console.log("setmark")
  // },
  printOrder: function(e) {
    var that = this;
    that.setData({
      printOrder: false,
    })
    wx.showToast({
      title: '功能开发中',
    })
  },
  onLoad: function(e) {
    var that = this
    console.log(e)
    if(e.status=='20'){
      that.setData({
        showMenu: false
      })
    }
    that.setData({
      deliveryNoteid: e.id
    })
    wx.request({
      url: app.data.baseUrl + '/transaction/DeliveryNoteMgrAction!listOrderForm',
      method: 'get',
      data: {
        'deliveryNote.id': e.id
      },
      header: app.globalData.header,
      success: function(res) {
        var rows = res.data.rows;
        console.log(res);

        that.setData({
          orderList: rows,
        });
      },
      fail: function(e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })

  }



})